import 'package:flutter/material.dart';
import 'package:untitled/utils/SnackBarHepler.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      scaffoldMessengerKey: ScaffoldMessengerGlobalKey,
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage>
    with SingleTickerProviderStateMixin {
  bool isSelect = false;
  @override
  Widget build(BuildContext context) {
    //脚手架
    return Scaffold(
      appBar: AppBar(
        title: Text('开关'),
        backgroundColor: Colors.blue,
        foregroundColor: Colors.white,
      ),

      body: SizedBox.expand(
        child: Column(
          children: [
            Switch(
              value: isSelect,
              //开关打开时  拇指颜色
              activeThumbColor: Colors.red,
              //开关打开时  轨道颜色
              activeTrackColor: Colors.green,
              //关闭时 拇指颜色
              inactiveThumbColor: Colors.orange,
              //关闭时  轨道颜色
              inactiveTrackColor: Colors.black,
              //轮廓的颜色
              trackOutlineColor: WidgetStateProperty.all(Colors.red),
              //轮廓的宽度
              trackOutlineWidth: WidgetStateProperty.all(3),
              onChanged: (bool value) {
                setState(() {
                  isSelect = value;
                });
              },
            ),

            SizedBox(height: 40),

            SwitchListTile(
              //第一行
              title: Text('是否开启音乐 '),
              //第二行
              subtitle: Text("开记音乐后 ddddd"),
              //控制开关的位置
              controlAffinity: ListTileControlAffinity.trailing,
              //左侧的图标
              secondary: Icon(Icons.home),
              value: isSelect,
              onChanged: (bool value) {
                setState(() {
                  isSelect = value;
                });
              },
            ),
          ],
        ),
      ),
    );
  }
}
